unit uXml_Item_Templates;

interface

uses
  Windows, SysUtils, Classes, StrUtils, NativeXml;

type
  TEnchant = class(TXmlNode)
  end;

  TModifier = class(TXmlNode)
  end;

  TModifiers = class(TXmlNode)
  protected
    function GetModifier(Index:Integer):TModifier;
  public
    property Modifier[Index:Integer]:TModifier read GetModifier;
  end;

  TWeapon_Stats = class(TXmlNode)
  end;

  TIdian = class(TXmlNode)
  end;

  TItem_Template = class(TXmlNode)
  protected
    function Getid:string;
    function Getname:string;
    function Getlevel:Integer;
    function Getmask:string;
    function Getweapon_type:string;
    function Getmax_stack_count:Integer;
    function Getitem_type:string;
    function Getquality:string;   
    function Getcategory:string;
    function Getprice:Integer;
    function Getrace:string;
    function Getrestrict:string;
    function Getdesc:Integer;
    function Getattack_type:string;
    function Getslot:Integer;
    function Getequipment_type:string;  
    function Getarmor_type:string;


    function GetEnchant:TEnchant;     
    function GetModifiers:TModifiers;
    function GetWeapon_Stats:TWeapon_Stats;
    function GetIdian:TIdian;

  public
    property id:string read Getid;
    property name:string read Getname;
    property level:Integer read Getlevel;
    property mask:string read Getmask;
    property weapon_type:string read Getweapon_type;   
    property max_stack_count:Integer read Getmax_stack_count;
    property item_type:string read Getitem_type;
    property quality:string read Getquality;
    property category:string read Getcategory;
    property price:Integer read Getprice;
    property race:string read Getrace;
    property restrict:string read Getrestrict;
    property desc:Integer read Getdesc;
    property attack_type:string read Getattack_type;
    property slot:Integer read Getslot;
    property equipment_type:string read Getequipment_type;
    property armor_type:string read Getarmor_type;

    property Enchant:TEnchant read GetEnchant;
    property Modifiers:TModifiers read GetModifiers;
    property Weapon_Stats:TWeapon_Stats read GetWeapon_Stats;    
    property Idian:TIdian read GetIdian;
  end;

  TItem_Templates = class(TNativeXml)
  protected
    function GetItem_Template(Index:Integer):TItem_Template;
  public
    property Item_Template[Index:Integer]:TItem_Template read GetItem_Template;
  end;

function Item_Templates(sfile:string):TItem_Templates;

implementation

function TItem_Templates.GetItem_Template(Index:Integer):TItem_Template;
begin 
  Result:=TItem_Template(Root.Nodes[Index]);
end;

function TModifiers.GetModifier(Index:Integer):TModifier;
begin
  Result:=TModifier(Nodes[Index]);
end;

function TItem_Template.Getid:string;
begin
  Result:=AttributeByName['id'];
end;

function TItem_Template.Getname:string;
begin
  Result:=AttributeByName['name'];
end;

function TItem_Template.Getlevel:Integer;
begin
  Result:=StrToIntDef(AttributeByName['level'],-1);
end;

function TItem_Template.Getmask:string;
begin
  Result:=AttributeByName['mask'];
end;

function TItem_Template.Getweapon_type:string;
begin
  Result:=AttributeByName['weapon_type'];
end;

function TItem_Template.Getmax_stack_count:Integer;
begin
  Result:=StrToIntDef(AttributeByName['max_stack_count'],0);
end;

function TItem_Template.Getitem_type:string;
begin
  Result:=AttributeByName['item_type'];
end;

function TItem_Template.Getquality:string;
begin
  Result:=AttributeByName['quality'];
end;

function TItem_Template.Getcategory:string;
begin
  Result:=AttributeByName['category'];
end;

function TItem_Template.Getprice:Integer;
begin
  Result:=StrToIntDef(AttributeByName['price'],0);
end;

function TItem_Template.Getrace:string;
begin
  Result:=AttributeByName['race'];
end;

function TItem_Template.Getrestrict:string;
begin
  Result:=AttributeByName['restrict'];
end;

function TItem_Template.Getdesc:Integer;
begin
  Result:=StrToIntDef(AttributeByName['desc'],0);
end;

function TItem_Template.Getattack_type:string;
begin
  Result:=AttributeByName['attack_type'];
end;

function TItem_Template.Getslot:Integer;
begin
  Result:=StrToIntDef(AttributeByName['slot'],0);
end;

function TItem_Template.Getequipment_type:string;
begin
  Result:=AttributeByName['equipment_type'];
end;

function TItem_Template.Getarmor_type:string;
begin
  Result:=AttributeByName['armor_type'];
end;

function TItem_Template.GetEnchant:TEnchant;
begin
  Result:=TEnchant(NodeFindOrCreate('enchant'));
end;

function TItem_Template.GetModifiers:TModifiers;
begin
  Result:=TModifiers(NodeFindOrCreate('modifiers'));
end;

function TItem_Template.GetWeapon_Stats:TWeapon_Stats;
begin   
  Result:=TWeapon_Stats(NodeFindOrCreate('weapon_stats'));
end;

function TItem_Template.GetIdian:TIdian;
begin 
  Result:=TIdian(NodeFindOrCreate('idian'));
end;

function Item_Templates(sfile:string):TItem_Templates;
begin
  Result:=TItem_Templates.Create;
  try
    if FileExists(sfile) then Result.LoadFromFile(sfile);
  except
  end;
end;

end.
